var app = getApp()
var IP = app.globalData.IP
Page({

  /**
   * 页面的初始数据
   */

  data: {
    identity: '',
    addressList: [],


    newAddress: {},
    deliveryAddressIndex: {},
    openid: "",
    deliveryAddressList: [],
  },
  //获取地址列表
  getAddressList() {
    wx.request({
      url: `http://${IP}:8080/user/getAddressListByOpenId/` + this.data.openid,
      success: res => {
        this.setData({
          deliveryAddressList: res.data
        })

     
      }
    })

  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(option) {
    this.setData({
      openid: wx.getStorageSync('openid')
    })

    //接收eventChannel传来的数据
    const eventChannel = this.getOpenerEventChannel()
    var that = this
    eventChannel.on('identity', function (data) {
      that.setData({
        identity: data.identity
      })
    })

  },

  sendAddressTodetail(e) {

    if (this.data.identity == 'serviceDetail') {


      const eventChannel = this.getOpenerEventChannel()
      eventChannel.emit('acceptDataFromDeliveryAddress', {
        username: e.currentTarget.dataset.username,
        telnumber: e.currentTarget.dataset.telnumber,
        provincename: e.currentTarget.dataset.provincename,
        cityname: e.currentTarget.dataset.cityname,
        countyname: e.currentTarget.dataset.countyname,
        detailinfo: e.currentTarget.dataset.detailinfo,
      });
      wx.navigateBack()


    }
  },



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getAddressList()

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})